<?php
/**
 * Handles all object loading
 *
 * @author Mark Dohmen.
 */
final class ObjectManager {
	
	/**
	 * Loads all objects from the database
	 * and registers them with the world.
	 */
	final public function load() {
		$data = Database::getDatabase()->fetchArray("SELECT * FROM `object_definitions`");
		foreach ($data as $definition) {
			if (ObjectDefintion::forId($definition['id']) === NULL) {
				ObjectDefintion::addDefinition(
					new ObjectDefintion($definition['id'], $definition['name'], $definition['description'])
				);
			}
		}
		$data = Database::getDatabase()->fetchArray("SELECT * FROM `objects`");
		foreach ($data as $object) {
			World::getWorld()->registerObject(
				new Object(
					new Location($object['xpos'], $object['ypos']), 
					ObjectDefintion::forId($object['id'])
				)
			);
		}
	}
}
?>